<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="物业名称" prop="pmid">
        <el-select v-model="queryParams.pmid" placeholder="请输入物业名称" clearable>
          <el-option
            v-for="item in carsManagement"
            :key="item.pmid"
            :label="item.propertyName"
            :value="item.pmid"
            @keyup.enter.native="handleQuery">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="车场名称" prop="hpid">
        <el-select v-model="queryParams.hpid" placeholder="请输入车场名称" clearable>
          <el-option
            v-for="item in carsHome"
            :key="item.chid"
            :label="item.chname"
            :value="item.chid"
            @keyup.enter.native="handleQuery">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="设备IP" prop="sheip">
        <el-input
          v-model="queryParams.sheip"
          placeholder="请输入设备IP"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['sys-cars:operation:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="operationList">
      <el-table-column label="序号" align="center" prop="orid"/>
      <el-table-column label="物业名称" align="center" prop="propertyManagement.propertyName"/>
      <el-table-column label="车场名称" align="center" prop="carsHome.chname"/>
      <el-table-column label="设备名称" align="center" prop="carsHomeLane.lanename"/>
      <el-table-column label="设备ip" align="center" prop="sheip"/>
      <el-table-column label="类型" align="center" prop="carsHomeLane.lanetype" :formatter="opertype"/>
      <el-table-column label="设备状态" align="center" prop="operstatus">
        <template slot-scope="scope">
          <el-button type="primary" plain disabled v-if="scope.row.operstatus==0">上线</el-button>
          <el-button type="danger" plain disabled v-else="scope.row.operstatus!=0">下线</el-button>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime"/>
      <el-table-column label="备注" align="center" prop="operationRemark" :formatter="remark"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

  </div>
</template>

<script>
import {listOperation, getOperation, delOperation, addOperation, updateOperation} from "@/api/pxy-cars/operation";
import {listHome} from "@/api/pxy-cars/home";
import {listManagement} from "@/api/pxy-cars/management";

export default {
  name: "Operation",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备记录表格数据
      operationList: [],
      carsManagement: [],
      carsHome: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pmid: null,
        hpid: null,
        sheip: null
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
    this.getHome();
    this.getManagement();
  },
  methods: {
    /** 查询设备记录列表 */
    getList() {
      this.loading = true;
      listOperation(this.queryParams).then(response => {
        this.operationList = response.rows;
        console.log(response)
        this.total = response.total;
        this.loading = false;
      });
    },
    getHome() {
      this.loading = true;
      listHome(this.queryParams).then(response => {
        this.carsHome = response.rows;
        // console.log(response.rows)
        this.loading = false;
      });
    },
    getManagement() {
      this.loading = true;
      listManagement(this.queryParams).then(response => {
        this.carsManagement = response.rows;
        // console.log(response.rows)
        this.loading = false;
      });
    },
    opertype(row) {
      return row.carsHomeLane.lanetype === 1 ? '出口' : '入口';
    },
    remark(row) {
      return row.operstatus == 0 ? '设备上线' : '设备下线'
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pxy-cars/operation/export', {
        ...this.queryParams
      }, `operation_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
